package com.markby.fscm.cryptogram.uitls;

import com.markby.fscm.constant.Constants;
import lombok.Getter;

import java.security.*;

public class RSAUtils {
    @Getter
    enum KeySize {
        SIZE_1024(1024),
        SIZE_2048(2048),
        SIZE_4096(4096);

        private final int size;

        KeySize(int size) {
            this.size = size;
        }

    }

    public static KeyPair generateKeyPair() throws NoSuchAlgorithmException, NoSuchProviderException {
        return generateKeyPair(2048);
    }

    public static KeyPair generateKeyPair(int keySize) throws NoSuchAlgorithmException, NoSuchProviderException {
        KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(Constants.RSA, GMBaseUtil.BC);
        keyPairGenerator.initialize(keySize, new SecureRandom());

        return keyPairGenerator.generateKeyPair();
    }
}
